package com.twu.bm.football;

import org.junit.Test;

import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

public class LeagueTest {

    PrintStream printStream = mock(PrintStream.class);
    Player player1Mock = mock(Player.class);
    Player player2Mock = mock(Player.class);
    Coach coachMock = mock(Coach.class);

    Set<Player> playerList = new HashSet<Player>();
    Set<Coach> coachList = new HashSet<Coach>();
    League league = new League(playerList, coachList);

    String playerHeading = "PLAYERS:";
    String coachHeading = "COACHES:";

    @Test
    public void shouldPrintOnePlayersWhenThereIsOnePlayer() {
        playerList = new HashSet<Player>();
        playerList.add(player1Mock);
        league = new League(playerList, coachList);

        league.print(printStream);
        verify(player1Mock).print(printStream);
    }

    @Test
    public void shouldPrintTwoPlayersWhenThereAreTwoPlayers() {
        playerList = new HashSet<Player>();
        playerList.add(player1Mock);
        playerList.add(player2Mock);
        league = new League(playerList, coachList);

        league.print(printStream);
        verify(player1Mock).print(printStream);
        verify(player2Mock).print(printStream);
    }

    @Test
    public void shouldCallCheckMatchesWhenSearchInputIsEntered() throws IOException {
        playerList = new HashSet<Player>();
        playerList.add(player1Mock);
        league = new League(playerList, coachList);

        String name = "anything";
        String number = "anything";

        league.matchPlayer(name, number);
        verify(player1Mock).checkMatches(name, number);
    }

    @Test
    public void shouldPrintPlayerAndCoachHeadersWhenPrintIsCalled() {
        league = new League(new HashSet<Player>(), new HashSet<Coach>());
        league.print(printStream);
        verify(printStream).println(playerHeading);
        verify(printStream).println(coachHeading);
    }

    @Test
    public void shouldPrintCoachesAndPlayersWhenPrintIsCalled() {
        playerList = new HashSet<Player>();
        playerList.add(player1Mock);

        coachList = new HashSet<Coach>();
        coachList.add(coachMock);
        league = new League(playerList, coachList);

        league.print(printStream);
        verify(player1Mock).print(printStream);
        verify(coachMock).print(printStream);
    }

}
